 //
//  MyAssertViewCell.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/7/1.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "MyAssertViewCell.h"

@interface MyAssertViewCell()

#define JudgeLogInUI ([ReadLoginData readLoginData].allKeys.count == 0)||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"0"])||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"1"])

/**
 *  数据数组
 */
@property (nonatomic,strong)NSArray *infoDataArray;

@property(nonatomic,strong)NSMutableArray *accountArray;

@end

@implementation MyAssertViewCell


- (instancetype)init
{
    if (self = [super init]) {  

    }
    return self;
}

- (void)setLogInDic:(NSDictionary *)logInDic {
    _logInDic = logInDic;
    
    [self setupUI];
}

- (void)setUserInfoNumberData:(NSDictionary *)userInfoNumberData {
    _userInfoNumberData = userInfoNumberData;
    
    self.infoDataArray = [self setUpUserInfoNumberData:userInfoNumberData];
}

- (NSArray *)setUpUserInfoNumberData:(NSDictionary *)infoDict {
    if (infoDict.count == 0) {
        return @[@"0.00",@"0.00",@"0.00",@"0.00"];
    } else {
        if (JudgeLogInUI) {
            // 个人
            return @[
                     [infoDict objectForKey:@"yue"],
                     [infoDict objectForKey:@"zongjifen"],
                     [infoDict objectForKey:@"jifenyue"],
                     [infoDict objectForKey:@"commission"]
                     ];
        } else {
            // 商家
            return @[
                     [infoDict objectForKey:@"yue"],
                     [infoDict objectForKey:@"zongjifen"],
                     [infoDict objectForKey:@"jifenyue"],
                     [infoDict objectForKey:@"yyye"]
                     ];
        }
    }
}

- (void)setupUI
{
    
    NSInteger count;
    
    count = 4;
    UILabel *accountLabel;
    UILabel *moneyLabel;
    for (int i = 0; i <count; i++) {
        NSArray *array = [NSArray array];
        if (JudgeLogInUI) {
            array = @[@"充值账户",@"代金券",@"积分权",@"我的佣金"];
        } else {
            array = @[@"充值账户",@"代金券",@"积分权",@"营业账户余额"];
        }
        self.accountArray  = [NSMutableArray arrayWithArray:array];
        accountLabel= [[UILabel alloc] init];
        accountLabel.textColor = [UIColor grayColor];
        [self addSubview:accountLabel];
        accountLabel.font = [UIFont systemFontOfSize:13];
        accountLabel.text = [NSString stringWithFormat:@"%@",self.accountArray[i]];
        accountLabel.textAlignment = NSTextAlignmentCenter;
        
        //
        moneyLabel= [[UILabel alloc] init];
        moneyLabel.textColor = [UIColor grayColor];
        [self addSubview:moneyLabel];
        moneyLabel.font = [UIFont systemFontOfSize:13];
        
        //覆盖button
        UIButton *tempBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:tempBtn];
        tempBtn.tag = 1992+i;
        [tempBtn addTarget:self action:@selector(assertViewTempButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        if (JudgeLogInData) {
            NSString *text = self.infoDataArray[i];
            
            moneyLabel.text =  [NSString stringWithFormat:@"%.2f",text.floatValue];
            
        } else {
            moneyLabel.text = @"0.00";
        }

        
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        
        [tempBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(WIDTH/count);
            make.height.mas_equalTo(HEIGHT/10);
            make.left.mas_equalTo(WIDTH/count*i);
            make.centerY.equalTo(self.mas_centerY);
            
        }];
        
        [accountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(WIDTH/count);
            make.height.mas_equalTo(self.Height/2);
            make.left.mas_equalTo(WIDTH/count*i);
            make.centerY.equalTo(self.mas_centerY).offset(10);
            
        }];
        
        
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(WIDTH/count);
            make.height.mas_equalTo(self.Height/2);
            make.left.mas_equalTo(WIDTH/count*i);
            make.centerY.equalTo(self.mas_centerY).offset(-12);
            
        }];
        
        
    }
}

- (void)assertViewTempButtonClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(assertViewDidClick:)]) {
        [self.delegate assertViewDidClick:button];
    }
    
}

#pragma mark >>>>>>>>>lazy
- (NSMutableArray *)accountArray
{
    if (!_accountArray) {
#warning 修改字段
//        if (JudgeLogInUI) {
//            _accountArray = @[@"充值账户",@"代金券",@"积分权",@"我的佣金"];
//        } else {
//            _accountArray = @[@"充值账户",@"代金券",@"积分权",@"营业账户余额"];
//        }
        
        _accountArray = [NSMutableArray array];
    }
    return _accountArray;
}

- (NSArray *)infoDataArray {
    if (!_infoDataArray) {
        _infoDataArray = [NSArray array];
    }
    return _infoDataArray;
}

@end
